package com.ccs.testdatas;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import com.ccs.functions.*;

public class Pos {

	
	public void pos(WebDriver driver) throws Exception{
		
		driver.manage().window().maximize();
		Login in = new Login();
		in.hcs(driver, "pharmacy");
		driver.findElement(By.xpath("//a[contains(.,'Outpatient Sales Ordering')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		WebElement patient = driver.findElement(By.xpath("//a[@id='patientToggle']"));
		WebElement guarantor = driver.findElement(By.xpath("//a[@id='guarantorToggle']"));
		WebElement order = driver.findElement(By.xpath("//a[@id='orderToggle']"));
		
		
		//PATIENT TOGGLE
		patient.click();
		PatientName name = new PatientName();
		String first = name.names(1);
		String fullName = "Cocolife, " + first;
		driver.findElement(By.xpath("//input[@id='patientName']")).sendKeys(fullName);
		
		//GUARANTOR TOGGLE
		guarantor.click();
		Select accountClass = new Select(driver.findElement(By.xpath("//select[@id='opsGuarantorBean.accountClassStr']")));
		accountClass.selectByVisibleText("HMO");
		driver.findElement(By.xpath("//input[@id='findGuarantor']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='bp_entity_finder_key']")).sendKeys("cocolife");
		driver.findElement(By.xpath("//div[@id='bpFinderForm']/div[2]/div[1]/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select relationship = new Select(driver.findElement(By.xpath("//select[@id='relationship']")));
		relationship.selectByVisibleText("GUARANTOR");
		driver.findElement(By.xpath("//input[@id='percent']")).click();
		driver.findElement(By.xpath("//input[@id='percentageLimit']")).clear();
		driver.findElement(By.xpath("//input[@id='percentageLimit']")).sendKeys("100");
		driver.findElement(By.xpath("//input[@id='add']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//ORDER TOGGLE
		order.click();
		driver.findElement(By.xpath("//input[@id='mServiceCode']")).sendKeys("044810101");
		driver.findElement(By.xpath("//div[@id='item_btn_div']/input[1]")).click();
		Thread.sleep(5000);
		driver.findElement(By.xpath("//input[@id='quantity']")).clear();
		driver.findElement(By.xpath("//input[@id='quantity']")).sendKeys("5");
		driver.findElement(By.xpath("//input[@id='addOrder']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//SUBMIT FORM
		driver.findElement(By.xpath("//input[@id='submitForm']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	
		
		
	}
	
	
}
